shadow:standard

Interface CanCompare<T>

Interfaces

shadow:standard@CanEqual<T>

interface CanCompare<T>

Interface CanCompare<T> specifies that a class can be compared to an object of type T, producing a signed comparison int. This interface allows overloading of the <, >, <=, and >= operators. If any of these operators is applied, the appropriate compare(T) method will be called and tested. This interface also supports the == operator through CanEqual<T>.

Method Summary

Modifiers Return Types Method and Description
public readonly (int) compare(T other)

Method called when the <, >, <=, or >= operator is applied.

Method Detail

compare

public readonly compare(T other) => (int)

Method called when the <, >, <=, or >= operator is applied. Should return -1, 0, or 1, if the current object is smaller than, equal to, or larger than the other object, respectively. The relation defined by this method should be transitive.

Parameters

other - object to compare to

Returns

whether smaller, equal, or larger